<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/avatar.jpg">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/avatar.jpg">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/avatar.jpg">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-big-counter.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"raphets.github.io","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"right","display":"hide","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"default"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="最近有个需求，在 App 内查看使用第三方签名的电子协议，电子协议为 PDF 文件。 上网查了一下，要实现 App 内在线查看 PDF，主要思路都是先把 PDF 文件下载下来，再通过 GitHub 第三方的库，打开 PDF 文件。">
<meta property="og:type" content="article">
<meta property="og:title" content="Android 实现应用内在线查看 PDF 文件">
<meta property="og:url" content="https://raphets.github.io/archives/c134fe48.html">
<meta property="og:site_name" content="尚拙">
<meta property="og:description" content="最近有个需求，在 App 内查看使用第三方签名的电子协议，电子协议为 PDF 文件。 上网查了一下，要实现 App 内在线查看 PDF，主要思路都是先把 PDF 文件下载下来，再通过 GitHub 第三方的库，打开 PDF 文件。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-06-28T10:01:14.000Z">
<meta property="article:modified_time" content="2022-05-25T02:42:58.003Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="PDF">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://raphets.github.io/archives/c134fe48.html">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Android 实现应用内在线查看 PDF 文件 | 尚拙</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">尚拙</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">一个分享技术、学习成长的个人博客网站</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-tool">

    <a href="/tool/" rel="section"><i class="fa fa-hammer fa-fw"></i>工具</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://raphets.github.io/archives/c134fe48.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="John Doe">
      <meta itemprop="description" content="不积跬步，无以至千里；不积小流，无以成江海。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="尚拙">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Android 实现应用内在线查看 PDF 文件
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-06-28 18:01:14" itemprop="dateCreated datePublished" datetime="2019-06-28T18:01:14+08:00">2019-06-28</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-05-25 10:42:58" itemprop="dateModified" datetime="2022-05-25T10:42:58+08:00">2022-05-25</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%8A%80%E6%9C%AF%E6%96%87%E7%AB%A0/" itemprop="url" rel="index"><span itemprop="name">技术文章</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%8A%80%E6%9C%AF%E6%96%87%E7%AB%A0/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>最近有个需求，在 App 内查看使用第三方签名的电子协议，电子协议为 PDF 文件。</p>
<p>上网查了一下，要实现 App 内在线查看 PDF，主要思路都是先把 PDF 文件下载下来，再通过 GitHub 第三方的库，打开 PDF 文件。</p>
<span id="more"></span>

<h2 id="参考文章"><a href="#参考文章" class="headerlink" title="参考文章"></a>参考文章</h2><p>使用腾讯TBS打开Office文件 <a target="_blank" rel="noopener" href="https://www.jianshu.com/p/8bd1c4918857">https://www.jianshu.com/p/8bd1c4918857</a></p>
<p>Android应用内展示word、excel、pdf、ppt等文件 <a target="_blank" rel="noopener" href="https://www.jianshu.com/p/3f57d640b24d">https://www.jianshu.com/p/3f57d640b24d</a></p>
<h2 id="常用的第三库："><a href="#常用的第三库：" class="headerlink" title="常用的第三库："></a>常用的第三库：</h2><h5 id="PdfViewPager"><a href="#PdfViewPager" class="headerlink" title="PdfViewPager"></a>PdfViewPager</h5><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">https://github.com/voghDev/PdfViewPager</span><br></pre></td></tr></table></figure>

<h5 id="AndroidPdfViewer"><a href="#AndroidPdfViewer" class="headerlink" title="AndroidPdfViewer"></a>AndroidPdfViewer</h5><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">https://github.com/barteksc/AndroidPdfViewer</span><br></pre></td></tr></table></figure>

<h5 id="android-pdfview"><a href="#android-pdfview" class="headerlink" title="android-pdfview"></a>android-pdfview</h5><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">https://github.com/JoanZapata/android-pdfview</span><br></pre></td></tr></table></figure>
<h5 id="腾讯浏览服务"><a href="#腾讯浏览服务" class="headerlink" title="腾讯浏览服务"></a>腾讯浏览服务</h5><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">https://tes.qq.com/tbs/guide.html</span><br></pre></td></tr></table></figure>
<p>这里我选择了使用腾讯浏览服务的　SDK　查看　PDF　文件。</p>
<p>主要步骤如下：</p>
<h1 id="一、下载腾讯浏览服务-SDK-并集成到应用"><a href="#一、下载腾讯浏览服务-SDK-并集成到应用" class="headerlink" title="一、下载腾讯浏览服务 SDK 并集成到应用"></a>一、下载腾讯浏览服务 SDK 并集成到应用</h1><p>腾讯浏览服务官网　<a target="_blank" rel="noopener" href="https://tes.qq.com/tbs/guide.html">https://tes.qq.com/tbs/guide.html</a></p>
<p>sdk中主要包含一个jar包和一个.so文件，将jar包和.so文件导入到lib目录</p>
<h1 id="二、NDK-设置"><a href="#二、NDK-设置" class="headerlink" title="二、NDK 设置"></a>二、NDK 设置</h1><p>打开对应 module 中的 build.gradle 文件,</p>
<p>在文件的 android{} 中的 defaultConfig{} 里，</p>
<p>添加如下配置: ndk{abiFilters “armeabi”}</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">android &#123;</span><br><span class="line">    defaultConfig &#123;</span><br><span class="line">        ndk &#123;</span><br><span class="line">            abiFilters &quot;armeabi-v7a&quot;, &quot;armeabi&quot;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">     sourceSets &#123;</span><br><span class="line">            main &#123;</span><br><span class="line">                jniLibs.srcDirs = [&#x27;libs&#x27;]</span><br><span class="line">            &#125;</span><br><span class="line">     &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="三、AndroidManifest-xml-里加入权限声明"><a href="#三、AndroidManifest-xml-里加入权限声明" class="headerlink" title="三、AndroidManifest.xml 里加入权限声明"></a>三、AndroidManifest.xml 里加入权限声明</h1><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;</span><br><span class="line"></span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;</span><br><span class="line"></span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot; /&gt;</span><br><span class="line"></span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;</span><br><span class="line"></span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; /&gt;</span><br></pre></td></tr></table></figure>

<h1 id="四、初始化-X５-内核"><a href="#四、初始化-X５-内核" class="headerlink" title="四、初始化 X５ 内核"></a>四、初始化 X５ 内核</h1><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">// 设置是否在没有WiFi的情况下下载内核   </span><br><span class="line">//QbSdk.setDownloadWithoutWifi(true);</span><br><span class="line">//初始化X5内核</span><br><span class="line">QbSdk.initX5Environment(this, new QbSdk.PreInitCallback() &#123;</span><br><span class="line">           @Override</span><br><span class="line">           public void onCoreInitFinished() &#123;</span><br><span class="line">           &#125;</span><br><span class="line">           @Override</span><br><span class="line">           public void onViewInitFinished(boolean b) &#123;</span><br><span class="line">              //x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。</span><br><span class="line">           &#125;</span><br><span class="line">       &#125;);</span><br></pre></td></tr></table></figure>

<h1 id="五、将-PDF-文件下载到本地，然后使用-SDK-里面的-TbsReaderView-打开-PDF-文件。"><a href="#五、将-PDF-文件下载到本地，然后使用-SDK-里面的-TbsReaderView-打开-PDF-文件。" class="headerlink" title="五、将 PDF 文件下载到本地，然后使用 SDK 里面的 TbsReaderView 打开 PDF 文件。"></a>五、将 PDF 文件下载到本地，然后使用 SDK 里面的 TbsReaderView 打开 PDF 文件。</h1><p>下载文件的方法，项目中是使用的 Retfrofit 和 Okhttp，并且进行了的封装，并不通用。所以下载文件的方法请自行编写。</p>
<h3 id="1、xml-布局页面"><a href="#1、xml-布局页面" class="headerlink" title="1、xml 布局页面"></a>1、xml 布局页面</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">&lt;android.support.v7.widget.LinearLayoutCompat</span><br><span class="line">    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span><br><span class="line">    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;</span><br><span class="line">    xmlns:tools=&quot;http://schemas.android.com/tools&quot;</span><br><span class="line">     android:id=&quot;@+id/ll_root&quot;</span><br><span class="line">    android:layout_width=&quot;match_parent&quot;</span><br><span class="line">    android:layout_height=&quot;match_parent&quot;</span><br><span class="line">    android:orientation=&quot;vertical&quot;</span><br><span class="line">    tools:context=&quot;.ui.activity.ReadPdfAgreementActivity&quot;&gt;</span><br><span class="line">    &lt;/android.support.v7.widget.LinearLayoutCompat&gt;</span><br></pre></td></tr></table></figure>
<h3 id="2、Activity-核心代码"><a href="#2、Activity-核心代码" class="headerlink" title="2、Activity 核心代码"></a>2、Activity 核心代码</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">public class ReadPdfAgreementActivity extends BaseAbstractActivity &#123;</span><br><span class="line"></span><br><span class="line">    @BindView(R.id.ll_root)</span><br><span class="line">    LinearLayoutCompat mLlRoot;</span><br><span class="line">    private String TAG = &quot;ReadPdfAgreementActivity&quot;;</span><br><span class="line">    private TbsReaderView mTbsReaderView </span><br><span class="line">    private String url;</span><br><span class="line">    </span><br><span class="line">    @Override</span><br><span class="line">    protected void onCreate() &#123;</span><br><span class="line">        ButterKnife.bind(this);</span><br><span class="line">        setContentView(R.layout.activity_read_pdf_agreement);</span><br><span class="line">        url = getIntent().getStringExtra(Constants.AGREEMENT_URL);</span><br><span class="line">        mTbsReaderView = new TbsReaderView(this, new TbsReaderView.ReaderCallback() &#123;</span><br><span class="line">                    @Override</span><br><span class="line">                    public void onCallBackAction(Integer integer, Object o, Object o1) &#123;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;);</span><br><span class="line">        mLlRoot.addView(mTbsReaderView, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));</span><br><span class="line">        downLoadPDF();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private void downLoadPDF() &#123;</span><br><span class="line"></span><br><span class="line">        RxRestClient.builder()</span><br><span class="line">                .url(url)</span><br><span class="line">                .build()</span><br><span class="line">                .download()</span><br><span class="line">                .subscribeOn(Schedulers.io())</span><br><span class="line">                .observeOn(AndroidSchedulers.mainThread())</span><br><span class="line">                .subscribe(new Observer&lt;ResponseBody&gt;() &#123;</span><br><span class="line">                    @Override</span><br><span class="line">                    public void onSubscribe(Disposable d) &#123;</span><br><span class="line"></span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    @Override</span><br><span class="line">                    public void onNext(ResponseBody responseBody) &#123;</span><br><span class="line">                        InputStream is = null;</span><br><span class="line">                        byte[] buf = new byte[2048];</span><br><span class="line">                        int len = 0;</span><br><span class="line">                        FileOutputStream fos = null;</span><br><span class="line">                        try &#123;</span><br><span class="line">                            is = responseBody.byteStream();</span><br><span class="line">                            long total = responseBody.contentLength();</span><br><span class="line">                            File fileDir = getAgreementCacheDir();</span><br><span class="line">                            if (!fileDir.exists()) &#123;</span><br><span class="line">                                fileDir.mkdirs();</span><br><span class="line">                            &#125;</span><br><span class="line">                             File fileN = getCacheFile(url);</span><br><span class="line">                             if (!fileN.exists()) &#123;</span><br><span class="line">                                boolean mkdir = fileN.createNewFile();</span><br><span class="line">                            &#125;else &#123;</span><br><span class="line">                                fileN.delete();</span><br><span class="line">                            &#125;</span><br><span class="line">                            fos = new FileOutputStream(fileN);</span><br><span class="line">                            long sum = 0;</span><br><span class="line">                            while ((len = is.read(buf)) != -1) &#123;</span><br><span class="line">                                fos.write(buf, 0, len);</span><br><span class="line">                                sum += len;</span><br><span class="line">                                int progress = (int) (sum * 1.0f / total * 100);</span><br><span class="line">                            &#125;</span><br><span class="line">                            fos.flush();</span><br><span class="line">                        </span><br><span class="line">                            displayPdfFile(fileN);</span><br><span class="line">                        &#125; catch (Exception e) &#123;</span><br><span class="line">                            PLog.d(TAG, &quot;文件下载异常 = &quot; + e.toString());</span><br><span class="line">                        &#125; finally &#123;</span><br><span class="line">                            try &#123;</span><br><span class="line">                                if (is != null)</span><br><span class="line">                                    is.close();</span><br><span class="line">                            &#125; catch (IOException e) &#123;</span><br><span class="line">                            &#125;</span><br><span class="line">                            try &#123;</span><br><span class="line">                                if (fos != null)</span><br><span class="line">                                    fos.close();</span><br><span class="line">                            &#125; catch (IOException e) &#123;</span><br><span class="line">                            &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    @Override</span><br><span class="line">                    public void onError(Throwable e) &#123;</span><br><span class="line">                        PLog.d(TAG, &quot;文件下载失败&quot;);</span><br><span class="line">                        File file = getCacheFile(url);</span><br><span class="line">                        if (!file.exists()) &#123;</span><br><span class="line">                            PLog.d(TAG, &quot;删除下载失败文件&quot;);</span><br><span class="line">                            file.delete();</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    @Override</span><br><span class="line">                    public void onComplete() &#123;</span><br><span class="line"></span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private void displayPdfFile(File file)&#123;</span><br><span class="line">        if (file != null &amp;&amp; !TextUtils.isEmpty(file.toString())) &#123;</span><br><span class="line">            //加载文件</span><br><span class="line">            Bundle localBundle = new Bundle();</span><br><span class="line">            localBundle.putString(&quot;filePath&quot;, file.toString());</span><br><span class="line">            localBundle.putString(&quot;tempPath&quot;, getExternalFilesDir(&quot;TbsReaderTemp&quot;).getAbsolutePath());</span><br><span class="line">            if (mTbsReaderView != null) &#123;</span><br><span class="line">                boolean bool = this.mTbsReaderView.preOpen(getFileType(mFile.toString()), false);</span><br><span class="line">                if (bool) &#123;</span><br><span class="line">                    mTbsReaderView.openFile(localBundle);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; </span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /***</span><br><span class="line">     * 获取缓存目录</span><br><span class="line">     *</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    private File getAgreementCacheDir() &#123;</span><br><span class="line">        String path = getExternalFilesDir(&quot;agreement&quot;).getAbsolutePath();</span><br><span class="line">        return new File(path);</span><br><span class="line">    &#125;</span><br><span class="line">    /***</span><br><span class="line">     * 绝对路径获取缓存文件</span><br><span class="line">     *</span><br><span class="line">     * @param url</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    private File getCacheFile(String url) &#123;</span><br><span class="line">        String fileName = &quot;agreement&quot; + &quot;.&quot; + getFileType(url);</span><br><span class="line">        File cacheFile = new File(getAgreementCacheDir(),fileName);</span><br><span class="line">        return cacheFile;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">  /***</span><br><span class="line">     * 获取文件类型</span><br><span class="line">     *</span><br><span class="line">     * @param paramString</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    private String getFileType(String paramString) &#123;</span><br><span class="line">        String str = &quot;&quot;;</span><br><span class="line"></span><br><span class="line">        if (TextUtils.isEmpty(paramString)) &#123;</span><br><span class="line">            return str;</span><br><span class="line">        &#125;</span><br><span class="line">        int i = paramString.lastIndexOf(&#x27;.&#x27;);</span><br><span class="line">        if (i &lt;= -1) &#123;</span><br><span class="line">            return str;</span><br><span class="line">        &#125;</span><br><span class="line">        str = paramString.substring(i + 1);</span><br><span class="line">        return str;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    protected void onDestroy() &#123;</span><br><span class="line">        super.onDestroy();</span><br><span class="line">        if (mTbsReaderView != null) &#123;</span><br><span class="line">            mTbsReaderView.onStopDisplay();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="3、退出-Activity-销毁-TbsReaderView"><a href="#3、退出-Activity-销毁-TbsReaderView" class="headerlink" title="3、退出 Activity 销毁 TbsReaderView"></a>3、退出 Activity 销毁 TbsReaderView</h3><p>退出页面时，一定要销毁 TbsReaderView，否则下次进来无法打开文件。</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">@Override</span><br><span class="line"> protected void onDestroy() &#123;</span><br><span class="line">     super.onDestroy();</span><br><span class="line">     if (mSuperFileview != null) &#123;</span><br><span class="line">         mSuperFileview.onStopDisplay();</span><br><span class="line">     &#125;</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>




    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/PDF/" rel="tag"><i class="fa fa-tag"></i> PDF</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/archives/cc128e34.html" rel="prev" title="Android 8.0 崩溃问题记录：Only fullscreen opaque activities can request">
      <i class="fa fa-chevron-left"></i> Android 8.0 崩溃问题记录：Only fullscreen opaque activities can request
    </a></div>
      <div class="post-nav-item">
    <a href="/archives/657e57a9.html" rel="next" title="Android 获取签名文件的证书指纹 MD5,SHA1,SHA256">
      Android 获取签名文件的证书指纹 MD5,SHA1,SHA256 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%AB%A0"><span class="nav-number">1.</span> <span class="nav-text">参考文章</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B8%B8%E7%94%A8%E7%9A%84%E7%AC%AC%E4%B8%89%E5%BA%93%EF%BC%9A"><span class="nav-number">2.</span> <span class="nav-text">常用的第三库：</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#PdfViewPager"><span class="nav-number">2.0.0.1.</span> <span class="nav-text">PdfViewPager</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#AndroidPdfViewer"><span class="nav-number">2.0.0.2.</span> <span class="nav-text">AndroidPdfViewer</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#android-pdfview"><span class="nav-number">2.0.0.3.</span> <span class="nav-text">android-pdfview</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E8%85%BE%E8%AE%AF%E6%B5%8F%E8%A7%88%E6%9C%8D%E5%8A%A1"><span class="nav-number">2.0.0.4.</span> <span class="nav-text">腾讯浏览服务</span></a></li></ol></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E4%B8%8B%E8%BD%BD%E8%85%BE%E8%AE%AF%E6%B5%8F%E8%A7%88%E6%9C%8D%E5%8A%A1-SDK-%E5%B9%B6%E9%9B%86%E6%88%90%E5%88%B0%E5%BA%94%E7%94%A8"><span class="nav-number"></span> <span class="nav-text">一、下载腾讯浏览服务 SDK 并集成到应用</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81NDK-%E8%AE%BE%E7%BD%AE"><span class="nav-number"></span> <span class="nav-text">二、NDK 设置</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81AndroidManifest-xml-%E9%87%8C%E5%8A%A0%E5%85%A5%E6%9D%83%E9%99%90%E5%A3%B0%E6%98%8E"><span class="nav-number"></span> <span class="nav-text">三、AndroidManifest.xml 里加入权限声明</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E5%88%9D%E5%A7%8B%E5%8C%96-X%EF%BC%95-%E5%86%85%E6%A0%B8"><span class="nav-number"></span> <span class="nav-text">四、初始化 X５ 内核</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%94%E3%80%81%E5%B0%86-PDF-%E6%96%87%E4%BB%B6%E4%B8%8B%E8%BD%BD%E5%88%B0%E6%9C%AC%E5%9C%B0%EF%BC%8C%E7%84%B6%E5%90%8E%E4%BD%BF%E7%94%A8-SDK-%E9%87%8C%E9%9D%A2%E7%9A%84-TbsReaderView-%E6%89%93%E5%BC%80-PDF-%E6%96%87%E4%BB%B6%E3%80%82"><span class="nav-number"></span> <span class="nav-text">五、将 PDF 文件下载到本地，然后使用 SDK 里面的 TbsReaderView 打开 PDF 文件。</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1%E3%80%81xml-%E5%B8%83%E5%B1%80%E9%A1%B5%E9%9D%A2"><span class="nav-number">0.1.</span> <span class="nav-text">1、xml 布局页面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2%E3%80%81Activity-%E6%A0%B8%E5%BF%83%E4%BB%A3%E7%A0%81"><span class="nav-number">0.2.</span> <span class="nav-text">2、Activity 核心代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3%E3%80%81%E9%80%80%E5%87%BA-Activity-%E9%94%80%E6%AF%81-TbsReaderView"><span class="nav-number">0.3.</span> <span class="nav-text">3、退出 Activity 销毁 TbsReaderView</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="John Doe"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">John Doe</p>
  <div class="site-description" itemprop="description">不积跬步，无以至千里；不积小流，无以成江海。</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">47</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">32</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2025</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">John Doe</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
